package com.zhoust.design.strategy.controller;

import com.zhoust.design.strategy.context.PayStrategyContext;
import com.zhoust.design.strategy.intf.PayStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhoushengtao
 * @version v1.0
 * @date 2021/11/1 21:02
 * @desc <todo something>
 */
@RestController
@Slf4j
public class TestPayController {

    @Autowired
    private PayStrategyContext payStrategyContext;

    @GetMapping("/testPay")
    public String testPay(@RequestParam String payCode){

        PayStrategy payStrategy = payStrategyContext.getPayStrategy(payCode);

        if(null == payStrategy){
            log.error("不存在该种支付方式。payCode:{}",payCode);
            return "err";
        }
        payStrategy.pay();
        payStrategy.payStatus("payId13288888");
        return "succeed";
    }

}
